<template >
  <div id="box">
    <div id="login">
      <h3>elm后台管理系统</h3>
      <el-form
        :model="ruleForm"
        status-icon
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-input
          type="text"
          v-model="ruleForm.pass"
          autocomplete="off"
        ></el-input>

        <el-input
          type="password"
          v-model="ruleForm.checkPass"
          autocomplete="off"
        ></el-input>

        <el-button type="primary" @click="fudebounce"
          >登录</el-button
        >
        <p>温馨提示:</p>
        <p>未登录过的新用户自动注册</p>
        <p>注册过的用户可凭账号密码登录</p>
      </el-form>
    </div>
  </div>
</template>
<script>
import instance from "../api"
import debounce from "../plugin/debounce.js"
export default {
  name:"Logoin",
  data(){
    return {
      ruleForm: {
        pass:"admin",
        checkPass:"123456"
      }
    }
  },
  created(){
    this.fnajax = debounce(this.fnsubmit)
  },
  methods:{
    fudebounce(){
      this.fnajax();
    },
    async fnsubmit(){
      let pass = this.ruleForm.pass;
      let checkPass = this.ruleForm.checkPass
      console.log(pass,checkPass)
      let {data} = await instance.get("user1",{params:{pass,checkPass}});
      console.log(data)
      let token = data[0].taken;
      localStorage.setItem("token",token)
      if(data.length > 0){
        this.$message({
          showClose: true,
          message: "登陆成功",
          type: "success",
          duration: 1000,
          onClose: () => {
            // alert("====")
            this.$router.push({ name: "Home" });
          }
        })
      }

    }
  }
}
</script>
<style scoped>
* {
  margin: 0;
  padding: 0;
}
#box {
  background: #324057;
  width: 100%;
  height: 700px;
}
#login {
  width: 350px;
  margin: 0px auto;
  padding-top: 100px;
}
h3 {
  text-align: center;
  color: #fff;
  margin-bottom: 50px;
  font-size: 34px;
}
.demo-ruleForm {
  background: #fff;
  padding: 0 20px;
}
.el-input {
  margin: 20px 0 0 0;
}
.el-button {
  width: 100%;
  margin: 20px 0;
  line-height: 30px;
}
p {
  color: red;
  text-align: center;
  margin-bottom: 5px;
  font-size: 12px;
}
.el-form {
  border-radius: 10px;
}
</style>
